home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 49.3 KB | 1,681 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UTECommands.cp
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UTECOMMANDS__
- #include "UTECommands.h"
- #endif
-
- // MacApp
-
- // #ifndef __UAPPLICATION__
- // #include "UApplication.h"
- // #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UDIALOG__
- #include "UDialog.h"
- #endif
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UFILE__
- #include "UFile.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UPATCH__
- #include "UPatch.h"
- #endif
-
- #ifndef __UPRINTHANDLER__
- #include "UPrintHandler.h"
- #endif
-
- #ifndef __USCROLLER__
- #include "UScroller.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __SCRAP__
- #include <Scrap.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- #if qDebug
-
- //----------------------------------------------------------------------------------------
- // DumpTTECommand:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDebug
-
- void DumpTTECommand(TTECommand* theTTECommand)
- {
- long oldStyleSize;
- long newStyleSize;
- long last;
-
- long oldDiff = Max(theTTECommand->fOldEnd - theTTECommand->fOldStart, 0);
- long newDiff = Max(theTTECommand->fNewEnd - theTTECommand->fNewStart, 0);
-
- fprintf(stderr, "old start/end, new start/end, diff :%1d/%1d, %1d/%1d, %1d \n", theTTECommand->fOldStart, theTTECommand->fOldEnd, theTTECommand->fNewStart, theTTECommand->fNewEnd, Max(oldDiff, newDiff));
- fprintf(stderr, "fTextPad :%1d\n", theTTECommand->fTextPad);
- fprintf(stderr, "fPadding size :%1d\n", GetHandleSize(theTTECommand->fPadding));
-
- oldStyleSize = 0;
- newStyleSize = 0;
- fprintf(stderr, "** Old styles:\n");
- if (theTTECommand->fOldStyles == NULL)
- fprintf(stderr, "NONE!\n");
- else
- {
-
- last = (*theTTECommand->fOldStyles)->scrpNStyles;
- fprintf(stderr, "Number of table entries: %1d\n", last);
- for (long i = 0; i <= last - 1; ++i)
- {
- ScrpSTElement & theScrpSTElement = (*theTTECommand->fOldStyles)->scrpStyleTab[i];
-
- fprintf(stderr, "%1d, ofs:%1d ", theScrpSTElement.scrpStartChar);
- fprintf(stderr, "\n");
- }
- oldStyleSize = GetHandleSize((Handle)(theTTECommand->fOldStyles));
- }
-
- fprintf(stderr, "** New styles:\n");
- if (theTTECommand->fNewStyles == NULL)
- fprintf(stderr, "NONE!\n");
- else
- {
- last = (*theTTECommand->fNewStyles)->scrpNStyles;
- fprintf(stderr, "Number of table entries: %1d\n", last);
- for (long i = 0; i <= last - 1; ++i)
- {
- ScrpSTElement & theScrpSTElement = (*theTTECommand->fNewStyles)->scrpStyleTab[i];
-
- fprintf(stderr, "%1d, ofs:%1d ", theScrpSTElement.scrpStartChar);
- fprintf(stderr, "\n");
- }
- newStyleSize = GetHandleSize((Handle)(theTTECommand->fNewStyles));
- }
-
- fprintf(stderr, "Styles size diff: %1d\n", Max(newStyleSize, oldStyleSize));
- fprintf(stderr, "fStylePad :%1d\n", theTTECommand->fStylePad);
- }
-
- #endif
-
-
- //========================================================================================
- // CLASS TTECommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment TESelCommand
- MA_DEFINE_CLASS_M1(TTECommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTECommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment TESelCommand
-
- TTECommand::TTECommand() :
- fHTE(NULL),
- fNewEnd(0),
- fNewStart(0),
- fNewStyles(NULL),
- fNewText(NULL),
- fOldEnd(0),
- fOldStart(0),
- fOldStyles(NULL),
- fOldText(NULL),
- fOldStaticText(),
- fPadding(NULL),
- fStylePad(0),
- fTEView(NULL),
- fEditText(NULL),
- fTextPad(0)
- {
- }
- // TTECommand::TTECommand
-
- //----------------------------------------------------------------------------------------
- // TTECommand::ITECommand:
- //----------------------------------------------------------------------------------------
- #pragma segment TESelCommand
-
- void TTECommand::ITECommand(TTEView* itsTEView,
- CommandNumber itsCommandNumber,
- Boolean itsSaveText)
- {
- short selChars;
- Handle h;
- TCommandHandler * theContext = NULL;
-
- if (itsTEView)
- theContext = itsTEView->GetContext(itsCommandNumber);
-
- ICommand(itsCommandNumber, theContext, kCanUndo, kCausesChange, theContext);
- fTEView = itsTEView;
- fEditText = itsTEView->GetEditText();
-
- fHTE = itsTEView->fHTE;
-
- {
- TERec & theTERec = **fHTE;
-
- fOldStart = theTERec.selStart;
- fOldEnd = theTERec.selEnd;
- selChars = theTERec.selEnd - theTERec.selStart;
- }
-
- FailInfo fi;
- Try(fi)
- {
- if (itsSaveText)
- {
- h = NewPermHandle(selChars);
-
- if (selChars > 0)
- MABlockMove((Ptr)((*((*fHTE)->hText)) + fOldStart), (*h), selChars);
-
- fOldText = h;
- fTextPad = fOldStart - fOldEnd;
- fPadding = NewPermHandle(0);
-
- if (fEditText)
- fEditText->TStaticText::GetText(fOldStaticText);
- }
-
- // TextEdit has this "feature" which it exercises if it runs out of memory. It's
- // called DS number 25. We'll try to avoid it by assuring that enough memory
- // exists to fulfill the request, but we won't die because of it. This is a
- // particularly ugly situation - there could be >600K of style information
- // associated with a 32K block of text. And to support undo, we've got to assume
- // that there may momentarily be THREE copies floating around, adding up to a
- // total potential liability of almost 2 Meg for a single TE record. The worst
- // that can happen, though, is that the text will be safe, but it won't have any
- // styles associated with it.
-
- if ((itsTEView->fStyleType == kWithStyle) && itsTEView->SpaceForStyles((*fHTE)->selStart, (*fHTE)->selEnd))
- {
- Boolean isPermAllocation = PermAllocation(TRUE);
- fOldStyles = TEGetStyleScrapHandle(fHTE);
- PermAllocation(isPermAllocation);
-
- FailNIL(fOldStyles);
-
- fStylePad = GetHandleSize((Handle)fOldStyles);
- }
-
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::ITECommand:
- //----------------------------------------------------------------------------------------
- #pragma segment TESelCommand
-
- void TTECommand::ITECommand(TEditText* itsEditText,
- CommandNumber itsCommandNumber,
- Boolean itsSaveText)
- {
- fEditText = itsEditText;
- AssureTEView();
- ITECommand(fTEView, itsCommandNumber, itsSaveText);
- ForgetTEView();
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- TTECommand::~TTECommand()
- {
- fOldText = DisposeIfHandle(fOldText);
- fOldStyles = (StScrpHandle)DisposeIfHandle((Handle)fOldStyles);
- fNewText = DisposeIfHandle(fNewText);
- fNewStyles = (StScrpHandle)DisposeIfHandle((Handle)fNewStyles);
- fPadding = DisposeIfHandle(fPadding);
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::AssureTEView:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::AssureTEView()
- {
- if (fEditText)
- {
- if (!fEditText->fTEView)
- fEditText->InstallFloatingTEView(FALSE);
-
- fTEView = fEditText->fTEView;
- fHTE = fTEView->fHTE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::ForgetTEView:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::ForgetTEView()
- {
- if (fEditText)
- {
- fTEView = NULL; // null these references so dependency
- fHTE = NULL; // notifications work correctly.
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::DoPostProcess
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::DoPostProcess()
- {
- if (fEditText)
- {
- TWindow * theWindow = fEditText->GetWindow();
- TEventHandler * windowTarget = theWindow ? theWindow->GetWindowTarget() : NULL;
-
- if (!theWindow || (windowTarget != fTEView && windowTarget != fEditText))
- {
- if (!fEditText->IsValid())
- SetValidationError((OSErr)kInvalidValue);
- fEditText->StopEdit();
- }
- ForgetTEView();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::BanishOldText:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::BanishOldText()
- {
- if (fOldEnd > fOldStart)
- TEDelete(fHTE);
- if (fPadding)
- SetPermHandleSize(fPadding, Max(-(fTextPad + fStylePad), 0));
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::InstallNewText:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::InstallNewText()
- {
- long savedSize;
- Handle itsText;
- SignedByte savedState;
-
- if (fNewEnd > fNewStart)
- {
- itsText = fTEView->fText;
- savedSize = GetHandleSize(itsText);
-
- #if qDebug
- if (fNewText == NULL)
- ProgramBreak("InstallNewText called with fNewText == NULL!");
- #endif
-
- savedState = LockHandleHigh(fNewText); // Prevent heap fragmentation for TEInsert
-
- if (fTEView->fStyleType == kWithStyle) // If record has style, use it
- TEStyleInsert((*fNewText), // It's okay for fNewStyles to be NULL here
- GetHandleSize(fNewText), fNewStyles, fHTE);
- else // Otherwise, do it the old-fashioned way
- TEInsert((*fNewText), GetHandleSize(fNewText), fHTE);
-
- HSetState(fNewText, savedState);
-
- if (GetHandleSize(itsText) <= savedSize)
- FailOSErr(memFullErr);
-
- fTEView->fSpecsChanged = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::RemoveAdditions:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::RemoveAdditions()
- {
- if (fNewText)
- {
- TESetSelect(fNewStart, fNewEnd, fHTE);
- TEDelete(fHTE);
- }
- if (fPadding)
- SetPermHandleSize(fPadding, Max(fTextPad + fStylePad, 0));
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::RestoreSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::RestoreSelection()
- {
- TESetSelect(fOldStart, fOldEnd, fHTE);
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::PrepareForUndoRedo:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TTECommand::PrepareForUndoRedo()
- {
- if (fEditText)
- fEditText->PrepareForUndoRedo(this);
- else if (fTEView)
- fTEView->PrepareForUndoRedo(this);
- else
- Inherited::PrepareForUndoRedo();
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::RevealUndoRedo:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TTECommand::RevealUndoRedo()
- {
- if (fEditText)
- fEditText->RevealUndoRedo(this);
- else if (fTEView)
- fTEView->RevealUndoRedo(this);
- else
- Inherited::RevealUndoRedo();
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::ReviveDeletions:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::ReviveDeletions()
- {
- Handle itsText;
- long savedSize;
- short nChars;
- SignedByte savedState;
-
-
- TESetSelect(fOldStart, fOldStart, fHTE); // so insert will take place at right point
- nChars = (short)GetHandleSize(fOldText); //!!! long->short
- if (nChars > 0)
- {
- itsText = fTEView->fText;
- savedSize = GetHandleSize(itsText);
-
- savedState = LockHandleHigh(fOldText); // Prevent heap fragmentation
-
- if (fTEView->fStyleType == kWithStyle) // If record has style, use it
- TEStyleInsert((*fOldText), nChars, // It's okay for fOldStyles to be NULL here
- fOldStyles, fHTE);
- else // Otherwise, do it the old-fashioned way
- TEInsert((*fOldText), nChars, fHTE);
-
- HSetState(fOldText, savedState);
-
- if (GetHandleSize(itsText) <= savedSize)
- FailOSErr(memFullErr);
-
- fTEView->fSpecsChanged = TRUE;
- }
-
- if (fEditText)
- fEditText->TStaticText::SetText(fOldStaticText, kDontRedraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::DoMainFunction:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::DoMainFunction()
- {
- if (fIdentifier != cCopy)
- BanishOldText();
- InstallNewText();
- if (fIdentifier != cCopy)
- fTEView->SynchView(kRedraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::SetupDependencies:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::SetupDependencies()
- {
- Inherited::SetupDependencies();
-
- if (CanBeUndone())
- {
- if (fEditText)
- fEditText->AddDependent(this);
- else if (fTEView)
- fTEView->AddDependent(this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::DoUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)// Override
- {
- if ((theChange == mClosed) && ((changedObject == fTEView) || changedObject == fEditText))
- fContext->CommitLastCommand();
- else
- Inherited::DoUpdate(theChange, changedObject, changedBy, dependencySpace);
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::DoIt() // override
- {
- AssureTEView();
- fTEView->Focus();
-
- DoMainFunction();
- #if qDebug
- if (TTEView::fgTEIntenseDebugging)
- DumpTTECommand(this);
- #endif
-
- DoPostProcess();
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::UndoIt() // override
- {
- AssureTEView();
- fTEView->Focus();
-
- RemoveAdditions();
- if (fOldText || !fOldStaticText.IsEmpty())
- ReviveDeletions();
- RestoreSelection();
- if (fIdentifier != cCopy)
- fTEView->SynchView(kRedraw);
- #if qDebug
- if (TTEView::fgTEIntenseDebugging)
- DumpTTECommand(this);
- #endif
-
- DoPostProcess();
- }
-
- //----------------------------------------------------------------------------------------
- // TTECommand::RedoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECommand::RedoIt() // override
- {
- AssureTEView();
- fTEView->Focus();
-
- RestoreSelection();
- DoMainFunction();
- #if qDebug
- if (TTEView::fgTEIntenseDebugging)
- DumpTTECommand(this);
- #endif
-
- DoPostProcess();
- }
-
-
- //========================================================================================
- // CLASS TTECutCopyCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TTECommand
-
- #pragma segment TESelCommand
- MA_DEFINE_CLASS_M1(TTECutCopyCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTECutCopyCommand::TTECutCopyCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TTECutCopyCommand::TTECutCopyCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTECutCopyCommand::ITECutCopyCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment TESelCommand
-
- void TTECutCopyCommand::ITECutCopyCommand(TTEView* itsTEView,
- CommandNumber itsCommandNumber)
- {
- fClipCreated = FALSE;
- ITECommand(itsTEView, itsCommandNumber, TRUE);
- fChangesClipboard = TRUE;
- fCausesChange = (itsCommandNumber != cCopy);
- fCanUndo = fCausesChange;
- }
-
- //----------------------------------------------------------------------------------------
- // TTECutCopyCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- TTECutCopyCommand::~TTECutCopyCommand()
- {
- if (fClipCreated)
- fOldText = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TTECutCopyCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECutCopyCommand::DoIt() // override
- {
- //TTECutCopyCommand.DoIt
- TextStyle clipStyle;
- VPoint itsSize;
- VRect itsMargins;
-
- MAVolatile(TTEView * , clipTEView);
-
- fTEView->Focus();
-
- SetTextStyle(clipStyle, applFont, 0, 12, gRGBBlack);// Initial style same as virgin TEView
-
- itsSize = VPoint(100, 50); // An arbitrary initial size.
- itsMargins = VRect(10, 8, 10, 0); // No bottom margin.
-
- clipTEView = new TTEView; // Create a new view for the clipboard
- clipTEView->ITEView(NULL, NULL, // Initialize view
- gZeroVPt, itsSize, sizeSuperView, sizeVariable, itsMargins, clipStyle, teFlushDefault, fTEView->fStyleType, fTEView->fAutoWrap);
- clipTEView->fAcceptsChanges = FALSE; // This is a read-only view
-
- // Cut can eat into temp memory so users can rescue text from overweight documents
- FailInfo fi;
- Try(fi)
- {
- if (!WillCauseChange()) // If Copy-ing, assure there's enough room
- FailSpaceIsLow();
- fi.Success();
- }
- else // Recover
- {
- clipTEView = (TTEView *)(FreeIfObject(clipTEView));
- fi.ReSignal();
- }
-
- clipTEView->StuffText(fOldText);
- FailSpaceIsLow();
-
- if (clipTEView->fStyleType == kWithStyle) // If record has style
- TEUseStyleScrap(0, SHRT_MAX, fOldStyles,// …then put in the styles
- kDontRedraw, clipTEView->fHTE);
- FailSpaceIsLow();
-
- clipTEView->fFreeText = TRUE; // Let TEView know it has to free the text
-
- ClaimClipboard(clipTEView); // Okay to claim (will call RecalcText!)
-
- fClipCreated = TRUE; // We be done
- DoMainFunction(); // Do the actual cut/copy
-
- #if qDebug
- if (TTEView::fgTEIntenseDebugging)
- {
- TTEView::DumpTERecord(clipTEView->fHTE);
- DumpTTECommand(this);
- }
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TTECutCopyCommand::ReviveDeletions:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTECutCopyCommand::ReviveDeletions() // override
- {
- if (fIdentifier == cCut)
- Inherited::ReviveDeletions(); // Don't do it for COPY
- }
-
-
- //========================================================================================
- // CLASS TTEPasteCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TTECommand
-
- #pragma segment TESelCommand
- MA_DEFINE_CLASS_M1(TTEPasteCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTEPasteCommand::TTEPasteCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TTEPasteCommand::TTEPasteCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTEPasteCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TTEPasteCommand::~TTEPasteCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTEPasteCommand::ITEPasteCommand: We can't use TEPaste because it clobbers the
- // DeskScrap; the text would be recoverable from the special TextEdit Scrap, but other
- // types of non-TEXT scrap are permanently lost, it seems
- //----------------------------------------------------------------------------------------
- #pragma segment TESelCommand
-
- void TTEPasteCommand::ITEPasteCommand(TTEView* itsTEView)
- {
- ITECommand(itsTEView, cPaste, TRUE); // Perform stock initializations
-
- MAVolatileInit(Handle, newText, NULL);
- MAVolatileInit(StScrpHandle, newStyles, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- newText = NewPermHandle(0); // Create handle to receive clipboard data
- if (itsTEView->fStyleType == kWithStyle)
- newStyles = (StScrpHandle)NewPermHandle(0);// Same for handle to receive style info
-
- ResType dataType = '%%%%';
- short newLength = (short)gClipboardMgr->GetDataToPaste(newText, dataType);//!!! long->short
-
- if (newLength > 0)
- {
- #if qDebug
- if (dataType != 'TEXT')
- ProgramBreak("TEPasteCommand given some non-text from clipboard");
- else
- #endif
-
- { // Prime "new" values
- fNewText = newText;
- fNewStart = (*fHTE)->selStart;
- fNewEnd = fNewStart + newLength;
- fTextPad = newLength - (fOldEnd - fOldStart);
-
- if (itsTEView->fStyleType == kWithStyle)
- {
- long newStyleLen = gClipboardMgr->fClipView->GivePasteData((Handle)newStyles, 'styl');
- if (newStyleLen > 0)
- {
- fNewStyles = newStyles;
- fStylePad = // Difference between old and new styles
- newStyleLen - fStylePad;
- }
- else
- newStyles = (StScrpHandle)DisposeIfHandle((Handle)newStyles);
- }
-
- if (fPadding)
- SetPermHandleSize(fPadding, Max(fTextPad + fStylePad, 0));
-
- FailSpaceIsLow();
- }
- }
- else
- {
- newText = DisposeIfHandle(newText);
- newStyles = (StScrpHandle)DisposeIfHandle((Handle)newStyles);
- }
-
- if (fEditText)
- {
- CStr255 aString;
- fEditText->GetText(aString);
- fEditText->TStaticText::SetText(aString, kDontRedraw);
- }
- fi.Success();
- }
- else // Recover
- {
- if (newText != fNewText) // newText is assigned to fNewText
- newText = DisposeIfHandle(newText);// …so avoid disposing twice.
- if (newStyles != fNewStyles) // Ditto for newStyles.
- newStyles = (StScrpHandle)DisposeIfHandle((Handle)newStyles);
- Free();
- fi.ReSignal();
- }
- }
-
-
- //========================================================================================
- // CLASS TTEStyleCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TTECommand
-
- #pragma segment TESelCommand
- MA_DEFINE_CLASS_M1(TTEStyleCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTEStyleCommand::TTEStyleCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TTEStyleCommand::TTEStyleCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTEStyleCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TTEStyleCommand::~TTEStyleCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTEStyleCommand::ITEStyleCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment TESelCommand
-
- void TTEStyleCommand::ITEStyleCommand(TTEView* itsTEView,
- const TextStyle& itsNewStyle,
- CommandNumber itsCommandNumber,
- short itsMode)
- {
- ITECommand(itsTEView, itsCommandNumber, FALSE);// Perform stock initialization, sans text
-
- fOldTextStyle = itsTEView->fTextStyle;
- fNewTextStyle = itsNewStyle;
-
- // Only do color change if we can
- if (qNeedsColorQD || HasColorQD())
- fMode = itsMode;
- else
- fMode = itsMode & ~doColor;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEStyleCommand::InstallOneStyle:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTEStyleCommand::InstallOneStyle(const TextStyle& newStyl)
- {
- fTEView->SetOneStyle(fOldStart, fOldEnd, fMode, newStyl, kRedraw);// Focus'es for us
- }
-
- //----------------------------------------------------------------------------------------
- // TTEStyleCommand::InstallManyStyles:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTEStyleCommand::InstallManyStyles(StScrpHandle newStyls)
- {
- fTEView->Focus();
- // No need to check for fStyleType, since we only get here if the record is stylish
- TEUseStyleScrap(fOldStart, fOldEnd, newStyls, kRedraw, fHTE);
-
- if (fOldEnd == fOldStart)
- {
- TextStyle theStyle;
-
- theStyle.tsFont = (*newStyls)->scrpStyleTab[0].scrpFont;
- theStyle.tsFace = (*newStyls)->scrpStyleTab[0].scrpFace;
- theStyle.tsSize = (*newStyls)->scrpStyleTab[0].scrpSize;
- theStyle.tsColor = (*newStyls)->scrpStyleTab[0].scrpColor;
-
- TESetStyle(doAll, &theStyle, kRedraw, fHTE);
- }
-
- fTEView->RecalcText(); // Might have changed number of lines
- fTEView->SynchView(kRedraw); // Show corrected view
-
- fTEView->fSpecsChanged = TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEStyleCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTEStyleCommand::DoIt() // override
- {
- TextStyle aTextStyle;
-
- aTextStyle = fNewTextStyle;
- InstallOneStyle(aTextStyle);
-
- #if qDebug
- if (TTEView::fgTEIntenseDebugging)
- DumpTTECommand(this);
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TTEStyleCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTEStyleCommand::UndoIt() // override
- {
- TextStyle aTextStyle;
- fTEView->Focus();
-
- RestoreSelection();
-
- if (fTEView->fStyleType == kWithoutStyle)
- {
- aTextStyle = fOldTextStyle;
- InstallOneStyle(aTextStyle);
- }
- else
- InstallManyStyles(fOldStyles);
- #if qDebug
- if (TTEView::fgTEIntenseDebugging)
- DumpTTECommand(this);
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TTEStyleCommand::RedoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTEStyleCommand::RedoIt() // override
- {
- fTEView->Focus();
- RestoreSelection();
- DoIt();
- }
-
-
- //========================================================================================
- // CLASS TTETypingCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TTECommand
-
- #pragma segment TESelCommand
- MA_DEFINE_CLASS_M1(TTETypingCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::TTETypingCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TTETypingCommand::TTETypingCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::ITETypingCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment TERes
-
- void TTETypingCommand::ITETypingCommand(TTEView* itsTEView,
- const CStr2& itsFirstCh)
- {
- ITECommand(itsTEView, cTyping, TRUE);
-
- FailInfo fi;
- Try(fi)
- {
-
- fNewStart = (*fHTE)->selStart; // Start and end are the same
- fNewEnd = fNewStart;
-
- fNewText = NULL;
- fNewText = NewPermHandle(0); // Allocate an empty block for text
-
- fCompleted = FALSE; // We've only just begun…
- fFirstChar = itsFirstCh; // Save character[s] for Doit
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment TERes
-
- TTETypingCommand::~TTETypingCommand()
- {
- if (fTEView->fTypingCommand == this)
- fTEView->fTypingCommand = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::DoNormalChar:
- //----------------------------------------------------------------------------------------
- #pragma segment TERes
-
- void TTETypingCommand::DoNormalChar(const CStr2& ch)
- {
- // Append char[s] to end of fNewText
-
- Boolean oldPerm = PermAllocation(TRUE);
- FailOSErr(PtrAndHand((Ptr) & ch[1], fNewText, ch.Length()));
- PermAllocation(oldPerm);
-
- fNewEnd += ch.Length(); // Bump both end of "selection"
- fTextPad += ch.Length(); // …and padding value
-
- // This SetPermHandleSize can't grow the handle,
- if (fPadding)
- SetPermHandleSize(fPadding, Max(-(fTextPad + fStylePad), 0));// …so it shouldn't fail.
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::BkSpcLeft: User has backspaced to the left of the original starting
- // point. First, copy the character (which may be more than one byte long if we are using
- // a non-Roman script) to a temporary buffer. The assumption is that no character will
- // ever be longer than four bytes. Sorry, folks, MacApp does not support typing in any
- // script with more than 4 billion characters. Next, copy the character to the front of
- // fOldText, and adjust fOldStart, fNewStart, and fNewEnd. Note that we do !check for
- // MemSpaceIsLow, since we want to let the user delete characters.
- //----------------------------------------------------------------------------------------
- #pragma segment TERes
-
- void TTETypingCommand::BkSpcLeft(Handle theText,
- short curStart)
- {
- unsigned char saveLength = 1;
- if (MACharacterByteType((*theText), curStart - 1, smCurrentScript) == smLastByte)
- saveLength++;
- curStart -= saveLength;
-
- CStr2 savedCh;
- savedCh.CopyFrom((void*)((*theText) + curStart), saveLength);
-
- if (fTEView->fStyleType == kWithStyle) // Only do this if styles are around
- {
- TextStyle delStyle;
- short theHeight;
- short theAscent;
- TEGetStyle(curStart, &delStyle, // Get the style of the deleted character
- &theHeight, &theAscent, fHTE);// (1 or 4 bytes, it's all only one style)
-
- if (!EqualBlocks((Ptr) & delStyle, // If style doesn't match first in the list
- (Ptr) & ((*fOldStyles)->scrpStyleTab[0].scrpFont), sizeof(TextStyle)))
- {
- // …then insert new style at head of list
- fTEView->fSpecsChanged = TRUE; // User backspaced into new style!
-
- long oldSize = // Make room for the new style element
- GetHandleSize((Handle)fOldStyles);
- SetPermHandleSize((Handle)fOldStyles, oldSize + sizeof(ScrpSTElement));
- fStylePad += sizeof(ScrpSTElement);
-
- {
- //ScrpSTElement & theScrpSTElement = (*fOldStyles)->scrpStyleTab[0];
- ScrpSTElement * theScrpSTElement = &(*fOldStyles)->scrpStyleTab[0];
-
- // MABlockMove(&(theScrpSTElement.scrpStartChar),// Move entire array up one element's size
- // (Ptr)&(theScrpSTElement.scrpStartChar) + sizeof(ScrpSTElement),
- // oldSize - sizeof((*fOldStyles)->scrpNStyles));
- MABlockMove(theScrpSTElement, (Ptr)theScrpSTElement + sizeof(ScrpSTElement), oldSize - sizeof(ScrpSTElement));
- }
-
- (*fOldStyles)->scrpNStyles++; // One more style
-
- {
- ScrpSTElement & theScrpSTElement = (*fOldStyles)->scrpStyleTab[0];
-
- theScrpSTElement.scrpHeight = theHeight;// Fill in the blanks
- theScrpSTElement.scrpAscent = theAscent;
- MABlockMove(&delStyle, &theScrpSTElement.scrpFont, sizeof(TextStyle));
- }
- }
-
- (*fOldStyles)->scrpStyleTab[0].scrpStartChar--;// Regardless, back off offset by one
- }
-
- if (fPadding)
- SetPermHandleSize(fPadding, GetHandleSize(fOldText) + savedCh.Length() + fStylePad);
- Munger(fOldText, 0, NULL, 0, &savedCh[1], savedCh.Length());
- FailMemError();
- fOldStart = curStart; // Treat this as though original selection
- fNewStart = curStart; // …had included this character
- fNewEnd = curStart;
- fTextPad -= savedCh.Length();
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::BkSpcRight:
- //----------------------------------------------------------------------------------------
- #pragma segment TERes
-
- void TTETypingCommand::BkSpcRight(Handle theText,
- short curStart)
- {
- short savedSize = 1;
- if (MACharacterByteType((*theText), curStart - savedSize, smCurrentScript) == smLastByte)
- ++savedSize;
- if (fPadding)
- SetPermHandleSize(fPadding, Max(-(fTextPad - savedSize + fStylePad), 0));
- fNewEnd -= savedSize;
- fTextPad -= savedSize;
-
- SetPermHandleSize(fNewText, fNewEnd - fNewStart);// Shouldn't fail as we're only shrinking it
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::FwdDelete: Forward delete courtesy of: Larry Goldman. Used by
- // permission.
- //----------------------------------------------------------------------------------------
- #pragma segment TERes
-
- void TTETypingCommand::FwdDelete(Handle theText,
- short curStart,
- short curEnd)
- {
- short theHeight;
- short theAscent;
- long oldSize;
- TextStyle delStyle;
- long oldTextSize;
-
- CStr2 savedCh;
-
- long textSize = GetHandleSize(theText);
- if ((curStart == curEnd) && (curStart < textSize))
- {
- unsigned char saveLength = 0; //Get the complete character
- if ((curStart + saveLength <= textSize) && (MACharacterByteType((*theText), curStart + saveLength, smCurrentScript) == smLastByte))
- ++saveLength;
- ++saveLength;
-
- savedCh.CopyFrom((void*)((*theText) + curStart), saveLength);
-
- if ((curStart >= fNewStart) && (curStart < fNewEnd))// char is within fNewText
- {
- // Remove the char from fNewText and update fNewEnd and fTextPad
- if (fPadding)
- SetPermHandleSize(fPadding, Max(-(fTextPad - savedCh.Length() + fStylePad), 0));
- fNewEnd -= savedCh.Length();
- fTextPad -= savedCh.Length();
-
- // Shouldn't fail as we're only shrinking it
- Munger(fNewText, curStart - fNewStart, NULL, savedCh.Length(), &savedCh[1], 0);
- FailMemError();
- }
- else // add char to the end of fOldChars, don't
- // update fOldEnd, but update fPadding
- {
- oldTextSize = GetHandleSize(fOldText);
- if (fTEView->fStyleType == kWithStyle)// Only do this if styles are around
- {
- TEGetStyle(curStart, &delStyle,// Get the style of the deleted character
- &theHeight, &theAscent, fHTE);// (1 or 4 bytes, it's all only one style)
-
- if (!EqualBlocks((Ptr) & delStyle,// If style doesn't match last in the list
- (Ptr) & (*fOldStyles)->scrpStyleTab[(*fOldStyles)->scrpNStyles - 1].scrpFont, sizeof(TextStyle)))
- {
- // …then insert new style at end of list
- fTEView->fSpecsChanged = TRUE;// User backspaced into new style!
-
- oldSize = GetHandleSize((Handle)fOldStyles);// Make room for the new style element
- SetPermHandleSize((Handle)fOldStyles, oldSize + sizeof(ScrpSTElement));
- fStylePad += sizeof(ScrpSTElement);
-
- (*fOldStyles)->scrpNStyles++;// One more style
-
- {
- ScrpSTElement & theScrpSTElement = (*fOldStyles)->scrpStyleTab[(*fOldStyles)->scrpNStyles - 1];
-
- theScrpSTElement.scrpStartChar = oldTextSize;
- theScrpSTElement.scrpHeight = theHeight;// Fill in the blanks
- theScrpSTElement.scrpAscent = theAscent;
- MABlockMove(&delStyle, &theScrpSTElement.scrpFont, sizeof(TextStyle));
- }
- }
- }
-
- if (fPadding)
- SetPermHandleSize(fPadding, oldTextSize + savedCh.Length() + fStylePad);
- Munger(fOldText, oldTextSize, NULL, 0, &savedCh[1], savedCh.Length());
- FailMemError();
- fTextPad = fTextPad - savedCh.Length();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::AddCharacter:
- //----------------------------------------------------------------------------------------
- #pragma segment TERes
-
- void TTETypingCommand::AddCharacter(const CStr2& ch)
- {
- Handle theText;
- short curSelStart;
- short curSelEnd;
- MAVolatile(Boolean, savedPerm);
-
- fTEView->Update(); // Makes sure that all of TE's actions are Visible
- fTEView->Focus();
-
- {
- TERec & theTERec = **fHTE;
-
- curSelStart = theTERec.selStart;
- curSelEnd = theTERec.selEnd;
- theText = theTERec.hText;
- }
-
- CWhileOutlinePreferred setOP(fTEView->fPreferOutline);
-
- FailInfo fi;
- Try(fi)
- {
- savedPerm = PermAllocation(TRUE);
-
- // Update the fNewText handle and other information. Note that because of
- // backspace, this can be tricky.*/
- if (ch == chFwdDelete) // User types forward delete, so keep in synch
- FwdDelete(theText, curSelStart, curSelEnd);
-
- else if (ch != chBackspace) // Not a backspace. Do the right thing
- DoNormalChar(ch);
-
- else if ((curSelStart <= fOldStart) && (curSelStart > 0) && (curSelStart == curSelEnd))// User typed backspace so keep in synch
- BkSpcLeft(theText, curSelStart); // Handle backspace to left of start
-
- else if (fNewEnd > fNewStart) // Delete 1 character from end of fNewText
- BkSpcRight(theText, curSelStart); // Handle backspace to right of start
-
- savedPerm = PermAllocation(savedPerm);
- fi.Success();
- }
- else // Recover
- {
- savedPerm = PermAllocation(savedPerm);
- fi.ReSignal();
- }
-
- if (ch != chFwdDelete)
- {
- // Let TextEdit have the character, as either 1) we're adding a byte, so we know
- // there is a reserve tank, so the worst this will do is eat into it a little, or
- // 2) we're deleting a character, which can only decrease memory usage.
-
- // NOTE: here is where we insert multibyte characters all at once
- TEKey(ch[1], fHTE);
- if (ch.Length() > 1)
- TEKey(ch[2], fHTE);
- }
- else if (curSelStart != curSelEnd) // forward delete with chars selected
- TEDelete(fHTE);
- else if (curSelStart < GetHandleSize(theText))
- {
- // forward delete with insertion point
- TEKey(chRight, fHTE);
- TEKey(chBackspace, fHTE);
- }
-
- fTEView->SynchView(kRedraw); // Now clean up the view.
-
- #if qDebugMsg
- if (TTEView::fgTEIntenseDebugging)
- {
- WrLblHandleContents("fOldText", fOldText);
- fprintf(stderr, "\n");
- WrLblHandleContents("fNewText", fNewText);
- fprintf(stderr, "\n");
- DumpTTECommand(this);
- }
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TERes
-
- void TTETypingCommand::DoIt() // override
-
- {
- AddCharacter(fFirstChar);
- #if qDebug
- if (TTEView::fgTEIntenseDebugging)
- DumpTTECommand(this);
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::RedoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTETypingCommand::RedoIt() // override
-
- {
- TextStyle currentStyle;
- short lineHeight;
- short fontAscent;
- Boolean resetStyle;
-
- if ((fOldEnd - fOldStart) == GetHandleSize(fOldText))
- {
- // No chars were vacuumed
- resetStyle = FALSE;
- if ((fTEView->fStyleType == kWithStyle) && (fOldEnd == fOldStart))
- {
- TEGetStyle(fOldStart, ¤tStyle, &lineHeight, &fontAscent, fHTE);
- resetStyle = !EqualBlocks((Ptr) & currentStyle, (Ptr) & (*fOldStyles)->scrpStyleTab[0].scrpFont, sizeof(TextStyle));
- }
-
- if (resetStyle) // The new text has a style of its own
- fNewStyles = fOldStyles; // Make InstallNewText insert styles, too
- Inherited::RedoIt();
- if (resetStyle)
- fNewStyles = NULL; // So fNewStyles doesn't get disposed
- }
- else
- {
- fTEView->Focus();
- TESetSelect(fOldStart, fOldStart + GetHandleSize(fOldText), fHTE);// select
- // vacuumed
- // chars, too
- TEDelete(fHTE); // Remove old text, including vacuumed chars
- if (fPadding)
- SetPermHandleSize(fPadding, Max(-(fTextPad + fStylePad), 0));
- InstallNewText();
- fTEView->SynchView(kRedraw);
- #if qDebug
- if (TTEView::fgTEIntenseDebugging)
- DumpTTECommand(this);
- #endif
-
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDoCommand
-
- void TTETypingCommand::UndoIt() // override
- {
- CompleteTyping();
- Inherited::UndoIt();
- }
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand::CompleteTyping:
- //----------------------------------------------------------------------------------------
- #pragma segment TERes
-
- void TTETypingCommand::CompleteTyping()
- {
- fCompleted = TRUE;
-
- if (fTEView->fStyleType == kWithStyle)
- {
- StScrpRec & theStScrpRec = **fOldStyles;
- long offset = -theStScrpRec.scrpStyleTab[0].scrpStartChar;
- if (offset > 0)
- for (short i = 0; i <= theStScrpRec.scrpNStyles - 1; ++i)
- theStScrpRec.scrpStyleTab[i].scrpStartChar += offset;
- }
- #if qDebug
- if (TTEView::fgTEIntenseDebugging)
- DumpTTECommand(this);
- #endif
-
- }
-
- #if qDrag
-
- //========================================================================================
- // CLASS TTEDragDropCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TTECommand
-
- #pragma segment MADragNonRes
- MA_DEFINE_CLASS_M1(TTEDragDropCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTEDragDropCommand::TTEDragDropCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TTEDragDropCommand::TTEDragDropCommand()
- {
- fNewStyles = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragDropCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TTEDragDropCommand::~TTEDragDropCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragDropCommand::ITEDragDropCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTEDragDropCommand::ITEDragDropCommand(TTEView* itsTEView,
- CommandNumber itsCommandNumber)
- {
- ITECommand(itsTEView, itsCommandNumber, FALSE);
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragDropCommand::ITEDragDropCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTEDragDropCommand::ITEDragDropCommand(TEditText* itsEditText,
- CommandNumber itsCommandNumber)
- {
- ITECommand(itsEditText, itsCommandNumber, FALSE);
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragDropCommand::DoMainFunction:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTEDragDropCommand::DoMainFunction()
- {
- InstallNewText();
- fTEView->SynchView(kRedraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragDropCommand::SetNewText:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTEDragDropCommand::SetNewText(Handle newText,
- StScrpHandle newStyles)
- {
- fNewText = newText;
- fNewEnd = fNewStart + (short)GetHandleSize(newText);// correct for text size
- fNewStyles = newStyles;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragDropCommand::SetNewStart:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTEDragDropCommand::SetNewStart(short newStart)
- {
- short textSize = fNewEnd - fNewStart;
- fNewStart = newStart;
- fNewEnd = fNewStart + textSize;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragDropCommand::InstallNewText:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTEDragDropCommand::InstallNewText()
- {
- VRect textEditArea(fTEView->GetExtent());
- fTEView->SetSelection(fNewStart, fNewStart, kRedraw);
- fTEView->Draw(textEditArea);
- Inherited::InstallNewText();
- // fTEView->SetSelection(fNewStart, fNewEnd, kRedraw);
- fTEView->Draw(textEditArea);
- }
-
- //========================================================================================
- // CLASS TTEDragMoveCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TTECommand
-
- #pragma segment MADragNonRes
- MA_DEFINE_CLASS_M1(TTEDragMoveCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTEDragMoveCommand::TTEDragMoveCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TTEDragMoveCommand::TTEDragMoveCommand()
- {
-
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragMoveCommand::Free:
- //----------------------------------------------------------------------------------------
- TTEDragMoveCommand::~TTEDragMoveCommand()
- {
- // fNewText and fOldText share a handle in this command. fNewText is NULLed to
- // prevent double disposal in the inherited Free().
- fNewText = NULL;
- fNewStyles = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragMoveCommand::ITEDragMoveCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTEDragMoveCommand::ITEDragMoveCommand(TTEView* itsTEView,
- CommandNumber itsCommandNumber,
- short newStart)
- {
- // initialize the command, and save the selection into fOldText
- ITECommand(itsTEView, itsCommandNumber, TRUE);
-
- // fOldStart and fOldEnd represent the text being dragged
- // fNewStart takes its impending relocation into account
- fNewStart = (fOldStart < newStart) ? (newStart - (fOldEnd - fOldStart)) : newStart;
- fNewEnd = fNewStart + (fOldEnd - fOldStart);
-
- // since new and old text are the same, the text handle can be shared
- fNewText = fOldText;
- fNewStyles = fOldStyles;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragMoveCommand::ITEDragMoveCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTEDragMoveCommand::ITEDragMoveCommand(TEditText* itsEditText,
- CommandNumber itsCommandNumber,
- short newStart)
- {
- // initialize the command, and save the selection into fOldText
- ITECommand(itsEditText, itsCommandNumber, TRUE);
-
- // fOldStart and fOldEnd represent the text being dragged
- // fNewStart takes its impending relocation into account
- fNewStart = (fOldStart < newStart) ? (newStart - (fOldEnd - fOldStart)) : newStart;
- fNewEnd = fNewStart + (fOldEnd - fOldStart);
-
- // since new and old text are the same, the text handle can be shared
- fNewText = fOldText;
- fNewStyles = fOldStyles;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDragMoveCommand::InstallNewText:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTEDragMoveCommand::InstallNewText()
- {
- // set the text insertion point
- TESetSelect(fNewStart, fNewStart, fHTE);
-
- Inherited::InstallNewText();
-
- TESetSelect(fNewStart, fNewEnd, fHTE);
- }
-
- #endif // qDrag
-
- //----------------------------------------------------------------------------------------
- // End of UTECommands.cp
-
- #pragma segment Inline
-
-